//
//  SISSTransferReservationShowViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/12/26.
//  Copyright © 2018 优房网. All rights reserved.
//

#import "SISSTransferReservationShowViewController.h"

#import "SISSTitleView.h"
#import "SISSShowView.h"
#import "SISSChooseView.h"
#import "SISSHouseProgressViewController.h"
#import "SISSPassengerProgressViewController.h"
#import "SISSTransferReservationViewController.h"
#import "SISSTextShowViewController.h"
#import "SISSNetworkingManager+HouseProgress.h"

@interface SISSTransferReservationShowViewController ()<SISSChooseViewDelegate>

/// 预约信息
@property (weak, nonatomic) SISSTitleView *reserveTitleView;
@property (weak, nonatomic) SISSShowView *servicePointShowView;
@property (weak, nonatomic) SISSShowView *timeShowView;
@property (weak, nonatomic) SISSShowView *addressShowView;
@property (weak, nonatomic) SISSChooseView *chooseView;
/// 业主所需资料
@property (weak, nonatomic) SISSTitleView *requiredInfoTitleView;
@property (weak, nonatomic) UILabel *requiredInfoLabel;
@property (weak, nonatomic) SISSTitleView *buyerFileTitleView;
@property (weak, nonatomic) UILabel *buyerFileLabel;
/// 注意事项
@property (weak, nonatomic) SISSTitleView *noticeTitleView;
@property (weak, nonatomic) UILabel *noticeLabel;


/// 编辑 上传
@property (weak, nonatomic) UIButton *editButton;

///
@property (strong, nonatomic) SISSBusinessContractNotaryModel *transferReservationModel;

@end

@implementation SISSTransferReservationShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"过户预约信息记录";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backItemAction)];
    [self requestData];
}

/**
 返回按钮点击事件
 */
- (void)backItemAction {
    
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[SISSHouseProgressViewController class]] || [controller isKindOfClass:[SISSPassengerProgressViewController class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

- (void)requestData {
    NSString *ahbpId = self.houseProgressModel ? self.houseProgressModel.ahbpId : self.passengerProgressRecordInfoModel.ahbpId;
    [kNetworkManager requestTransferReservationInfoWithAhbpId:ahbpId success:^(SISSBusinessContractNotaryModel *transferReservationModel) {
        self.transferReservationModel = transferReservationModel;
        if (self.isHistory && !transferReservationModel) {
            for (UIView *view in self.view.subviews) {
                view.hidden = YES;
            }
        }
    } failed:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
- (void)setTransferReservationModel:(SISSBusinessContractNotaryModel *)transferReservationModel {
    _transferReservationModel = transferReservationModel;
    self.servicePointShowView.rightStr = transferReservationModel.address;
    self.timeShowView.rightStr = transferReservationModel.applyTime;
    self.addressShowView.rightStr = transferReservationModel.addressDetail;
    self.requiredInfoLabel.text = transferReservationModel.sellerFile;
    self.buyerFileLabel.text = transferReservationModel.buyerFile;
    self.noticeLabel.text = transferReservationModel.attention;
    
}

#pragma mark - SISSChooseViewDelegate
- (void)clickChooseActionWithChooseView:(SISSChooseView *)chooseView {
    SISSTextShowViewController *vc = [[SISSTextShowViewController alloc] init];
    vc.title = @"不动产登记预约须知";
    vc.textStr = @"  一、预约人对现场办理时需提交申请材料和办事程序有疑问，可以点击“网厅办事指南” 进行了解。\n  二、网上预约申请采用实名制，预约人须为不动产登记申请人或相关当事人，并填写《预约申请表》。网上预约信息与现场所提供的身份证明及不动产权利证明不符的，不予发预约号。特别提示：当境外人士为待办业务的不动产权利人时，到各登记点取当前时段现场预约号即可办理。\n  三、预约人可以预约当天的预约号。同一个身份证号码同一预约日期同一预约业务事项（除抵押权注销登记外），只能预约一次。同一不动产同一预约业务事项，只能预约一次。特别提示:如同一不动产权利人，在同一天办理转移、抵押或变更多套不动产，只需预约一个号即可办理;预约“领取不动产权证书及登记证明”服务事项时，请务必留意受理通知书上的领证日期。\n  四、预约申请成功后，预约人须在预约时段开始前10分钟至结束前10分钟内凭预约回执或申请成功短信，并携带身份证明等相关资料到现场取号。如预约时段为9:00-10:00，取号时间为8:50-9:50。如需取消预约，应不晚于预约时段开始时间。\n  五、逾期未到现场取号者，视为失约，失约一次或五日内取消满两次的(含两次)，该预约人及权属证明编号将在未来五日内无法预约。\n  六、预约开放时间为7:00-23:00，其余时间停止服务。为防止恶意预约，系统已建立黑名单制度。";
    [self.navigationController pushViewController:vc animated:YES];
}


// 编辑按钮点击事件
- (void)editButtonClickAction {
    SISSTransferReservationViewController *vc = [[SISSTransferReservationViewController alloc] init];
    vc.houseProgressModel = self.houseProgressModel;
    vc.houseProgressRecordInfoModel = self.houseProgressRecordInfoModel;
    vc.passengerProgressModel = self.passengerProgressModel;
    vc.passengerProgressRecordInfoModel = self.passengerProgressRecordInfoModel;
    vc.transferReservationModel = self.transferReservationModel;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)setupSubviews {
    [super setupSubviews];
    
    SISSTitleView *reserveTitleView = [[SISSTitleView alloc] init];
    reserveTitleView.titleStr = @"预约公证";
    [self.containerView addSubview:reserveTitleView];
    self.reserveTitleView = reserveTitleView;
    
    SISSShowView *servicePointShowView = [[SISSShowView alloc] init];
    servicePointShowView.leftStr = @"受理服务点：";
    servicePointShowView.isShowBottomLine = YES;
    [self.containerView addSubview:servicePointShowView];
    self.servicePointShowView = servicePointShowView;
    
    SISSShowView *timeShowView = [[SISSShowView alloc] init];
    timeShowView.leftStr = @"预约时间段：";
    timeShowView.isShowBottomLine = YES;
    [self.containerView addSubview:timeShowView];
    self.timeShowView = timeShowView;
    
    SISSShowView *addressShowView = [[SISSShowView alloc] init];
    addressShowView.leftStr = @"地址：";
    addressShowView.isShowBottomLine = YES;
    [self.containerView addSubview:addressShowView];
    self.addressShowView = addressShowView;
    
    SISSChooseView *chooseView = [[SISSChooseView alloc] init];
    chooseView.leftStr = @"过户登记预约需知";
    chooseView.isShowBottomLine = YES;
    chooseView.delegate = self;
    [self.containerView addSubview:chooseView];
    self.chooseView = chooseView;
    
    SISSTitleView *requiredInfoTitleView = [[SISSTitleView alloc] init];
    requiredInfoTitleView.titleStr = @"业主所需资料";
    [self.containerView addSubview:requiredInfoTitleView];
    self.requiredInfoTitleView = requiredInfoTitleView;
    
    UILabel *requiredInfoLabel = [UILabel yyr_labelWithText:@"" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.containerView addSubview:requiredInfoLabel];
    self.requiredInfoLabel = requiredInfoLabel;
    
    SISSTitleView *buyerFileTitleView = [[SISSTitleView alloc] init];
    buyerFileTitleView.titleStr = @"客户所需资料";
    [self.containerView addSubview:buyerFileTitleView];
    self.buyerFileTitleView = buyerFileTitleView;
    
    UILabel *buyerFileLabel = [UILabel yyr_labelWithText:@"" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.containerView addSubview:buyerFileLabel];
    self.buyerFileLabel = buyerFileLabel;
    
    
    SISSTitleView *noticeTitleView = [[SISSTitleView alloc] init];
    noticeTitleView.titleStr = @"注意事项";
    [self.containerView addSubview:noticeTitleView];
    self.noticeTitleView = noticeTitleView;
    
    UILabel *noticeLabel = [UILabel yyr_labelWithText:@"" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self.containerView addSubview:noticeLabel];
    self.noticeLabel = noticeLabel;
    
    UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [editButton setTitle:@"编辑" forState:UIControlStateNormal];
    [editButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [editButton setBackgroundColor:MAIN_COLOR];
    [editButton addTarget:self action:@selector(editButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:editButton];
    self.editButton = editButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf;
    [self.reserveTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.servicePointShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.reserveTitleView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.timeShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.servicePointShowView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.addressShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.timeShowView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.chooseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.addressShowView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(6 * globelMargin);
    }];
    
    [self.requiredInfoTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.chooseView.mas_bottom);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.requiredInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.requiredInfoTitleView.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.containerView).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
        make.height.mas_equalTo(8 * globelMargin);
    }];
    
    [self.buyerFileTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.requiredInfoLabel.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.buyerFileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.buyerFileTitleView.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.containerView).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
        make.height.mas_equalTo(8 * globelMargin);
    }];
    
    [self.noticeTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.buyerFileLabel.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.noticeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.noticeTitleView.mas_bottom).offset(2 * globelMargin);
        make.left.equalTo(weakSelf.containerView).offset(2 * globelMargin);
        make.right.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
        make.height.mas_equalTo(8 * globelMargin);
        make.bottom.equalTo(weakSelf.containerView).offset(-5 * globelMargin);
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(weakSelf.mas_bottomLayoutGuideTop);
        make.centerX.equalTo(weakSelf.view);
        make.width.mas_equalTo(0.8 * SCREEN_WIDTH);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
}



@end
